package com.codergd.gra.controller;

import com.codergd.gra.bean.Com;
import com.codergd.gra.bean.Job;
import com.codergd.gra.bean.User;
import com.codergd.gra.bean.UserRe;
import com.codergd.gra.dao.ComDao;
import com.codergd.gra.dao.JobDao;
import com.codergd.gra.dao.UserDao;
import com.codergd.gra.service.UserReService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/userRe")
public class UserReController {

    @Autowired
    UserReService userReService;
    @Autowired
    UserRe userRe;

    @Autowired
    User user;
    @Autowired
    UserDao userDao;

    @Autowired
    Job job;
    @Autowired
    JobDao jobDao;

    @Autowired
    Com com;
    @Autowired
    ComDao comDao;

    //创建简历投递
    @PostMapping("/addUserRe")
    public int addUserRe(int uid,int jid){
        user = userDao.selectUserInfo(uid);
        job = jobDao.getJobById(jid);
        com = comDao.selectComById(job.getCom()).get(0);
        userRe.setState(0);
        userRe.setJid(jid);
        userRe.setUid(uid);
        userRe.setJob(job.getJob());
        userRe.setUname(user.getName());
        userRe.setSallow(job.getSallow());
        userRe.setSal(user.getSal());
        userRe.setContent(user.getContent());
        userRe.setResume(user.getResume());
        userRe.setCname(com.getComname());
        userRe.setAddress(com.getAddress());
        userRe.setCid(job.getCom());
        return userReService.addUserRe(userRe);
    }

    @PostMapping("/updateState")
    public int updateState(int id,int state){
        return userReService.updateState(id,state);
    }

    @PostMapping("/userReC")
    public List<UserRe> userReC(int cid){
        int state = 1;
        return userReService.userReC(cid,state);
    }

    @PostMapping("/userReC1")
    public List<UserRe> userReC1(int cid){
        int state = 2;
        return userReService.userReC1(cid,state);
    }

    @PostMapping("/userReC3")
    public List<UserRe> userReC3(int cid,int state){
        return userReService.userReC3(cid,state);
    }

    @PostMapping("/userReU")
    public List<UserRe> userReU(int uid,int state){
        return userReService.userReU(uid,state);
    }

    @PostMapping("/userReUM")
    public List<UserRe> userReUM(int uid){
        return userReService.userReUM(uid);
    }

    @PostMapping("/updatePy")
    public int updatePy(int id,String py){
        return userReService.updatePy(id, py);
    }

    @PostMapping("/updateScore")
    public int updateScore(int id,int score){
        return userReService.updateScore(id,score);
    }
}
